<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
// 按需引入 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts')
// 引入柱状图
require('echarts/lib/chart/pie')
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
import chartResize from './mixins/chart-resize.js'

export default {
  mixins:[chartResize],
  name:'Rose-chart',
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    // 数据对象属性 代表的意义
    // dataXa x轴配置的数据
    // y1Data y轴第一条数据
    // y2Data y轴第二条线的数据
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.chartEleResizeListener();
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      debugger
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions(this.chartData)
    },

    setOptions({ y1Data, y2Data } = {}) {
      this.chart.setOption({
        title: {
          text: '南丁格尔玫瑰图',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          top: 'bottom',
          data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6']
        },
        series: [
          {
            name: '面积模式',
            type: 'pie',
            radius: [30, 110],
            roseType: 'area',
            data: [
              {value: 10, name: 'rose1'},
              {value: 5, name: 'rose2'},
              {value: 15, name: 'rose3'},
              {value: 25, name: 'rose4'},
              {value: 20, name: 'rose5'},
              {value: 40, name: 'rose6'}
            ]
          }
        ]
      })
    },



    // initChart() {
    //   this.chart = echarts.init(this.$el)
    //   this.chart.setOption({
    //     title: {
    //       text: '南丁格尔玫瑰图',
    //       left: 'center'
    //     },
    //     tooltip: {
    //       trigger: 'item',
    //       formatter: '{a} <br/>{b} : {c} ({d}%)'
    //     },
    //     legend: {
    //       left: 'center',
    //       top: 'bottom',
    //       data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6']
    //     },
    //     series: [
    //       {
    //         name: '面积模式',
    //         type: 'pie',
    //         radius: [30, 110],
    //         roseType: 'area',
    //         data: [
    //             {value: 10, name: 'rose1'},
    //             {value: 5, name: 'rose2'},
    //             {value: 15, name: 'rose3'},
    //             {value: 25, name: 'rose4'},
    //             {value: 20, name: 'rose5'},
    //             {value: 40, name: 'rose6'}
    //         ]
    //       }
    //     ]
    //   })
    // }
  }
}
</script>
